<template>
  <div class="micro-notice-box component-notice">
    <div class="design-preview-controller">
      <div class="notice-content">
        <img
          class="iconfont_ckq ckq_notice"
          style="width: 40px;"
          src="@/assets/img/horn2.png"
          alt
        >
        <el-icon class="el-icon-arrow-right">
          <ArrowRight />
        </el-icon>
      </div>
    </div>
    <div
      v-show="isShowEdit"
      class="design-editor-item design-hide-class"
    >
      <div class="design-config-editor">
        <div class="design-editor-component-title">
          {{ $t('shopFeature.notice.announcement') }}
        </div>
        <div class="add-notice">
          <p>{{ $t('shopFeature.notice.announcementTips1') }}</p>
          <p>{{ $t('shopFeature.notice.announcementTips2') }}</p>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>

const props = defineProps({
  currentComponent: { // 当前组件
    type: Object,
    default: () => {}
  },
  indexKey: { // 当前组件排序索引 type_ + key
    type: String,
    default: ''
  },
  current: { // 当前排序索引 key
    type: Number,
    default: 0
  },
  isShowEdit: { // 是否为编辑状态
    type: Boolean,
    default: false
  },
  dataField: { // 所有上传到后端的字段
    type: Object,
    default: () => {
    }
  },
  isStartCheckFieldRules: { // 是否开始校验规则
    type: Boolean,
    default: false
  }
})
const emit = defineEmits(['myCheckResult', 'showCheckForm', 'componentsValueChance', 'save'])
const formData = reactive({
  title: $t('shopFeature.notice.announcement')
})

watch(() => props.dataField, (val) => {
  if (val) {
    setFormData()
  }
})
watch(() => props.isStartCheckFieldRules, () => {
  checkData()
})
watch(() => formData, (val) => {
  if (val) {
    emit('componentsValueChance', {
      indexKey: props.indexKey,
      current: props.current,
      dataField: val
    })
  }
}, {
  deep: true
})

onMounted(() => {
  setFormData()
})

/**
 * 开始验证
 */
const checkData = () => {
  myCheckResult(true)
}

/** 设置或者重设formData的数据 */
const setFormData = () => {
  if (props.dataField) {
    for (const el in props.dataField) {
      formData[el] = props.dataField[el]
    }
  }
}
/**
 * 返回校验结果
 * isHeader 是否为顶部 特殊情况
 * 结果：Boolean true false
 * */

const myCheckResult = ($isPass) => {
  emit('myCheckResult', {
    data: {
      isPass: $isPass,
      dataField: props.dataField,
      isHeader: (props.currentComponent.type.indexOf('config') !== -1),
      current: props.current
    }
  })
}

</script>

<style lang="scss" scoped>
@use './index.scss';
</style>
